<?php

namespace common\models\cms;

use Yii;
use common\helpers\Url;

/**
 * This is the model class for table "{{%cms_article_video}}".
 *
 * @property int $id
 * @property int $article_id 文章ID
 * @property string|null $path 视频地址
 * @property int $attach_id 附件ID
 * @property string|null $cover 视频封面地址
 * @property string|null $description 描述简介
 * @property int $listorder
 * @property int $duration 视频时长
 * @property int $size 视频大小
 * @property int $created_at
 * @property int $updated_at
 */
class CmsArticleVideo extends \common\db\ActiveRecord {

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%cms_article_video}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['article_id', 'attach_id', 'listorder', 'duration', 'size', 'created_at', 'updated_at'], 'integer'],
            [['path', 'cover', 'description'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'article_id' => '文章ID',
            'path' => '视频地址',
            'attach_id' => '附件ID',
            'cover' => '视频封面地址',
            'description' => '描述简介',
            'listorder' => 'Listorder',
            'duration' => '视频时长',
            'size' => '视频大小',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    public function getThumb() {
        return Url::attach($this->cover);
    }

    public function getSource() {
        return Url::video($this->path);
    }

    /**
     * 关联文章详情
     */
    public function getArticle() {
        return $this->hasOne(CmsArticle::class, ['id' => 'article_id']);
    }

}
